#!/bin/bash
#ubuntu安装docker
#参考链接：https://www.cnblogs.com/walker-lin/p/11214127.html
#author: Turboyan

case $1 in
	"-rm")	#卸载docker所有软件
		echo "即将删除所有docker相关软件，慎重操作，是否继续？y/n"
		read yesno
		if [ $yesno == "y" ]
		then
			sudo apt purge docker -y
			sudo apt purge docker-ce -y
			sudo apt purge docker-* -y
		else
			echo "取消删除，退出"
			exit
		fi
	;;
	"-rm_file")	#删除所有容器和镜像
		echo "即将删除所有容器和镜像，慎重操作，是否继续？y/n"
		read yesno
		if [ $yesno == "y" ]
		then
			sudo rm -rf /var/lib/docker	#删除所有镜像和容器
		else
			echo "取消删除，退出"
			exit
		fi
	;;
	"-permission")
		#sudo gpasswd -a turbo docker
		#sudo service docker restart
		#newgrp - docker
		sudo usermod -a -G docker $USER
	;;
	"-in_ubuntu_x86")
		sudo apt-get update
		sudo apt-get install \
			apt-transport-https \
			ca-certificates \
			curl \
			software-properties-common
		curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
		sudo add-apt-repository \
   			"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   			$(lsb_release -cs) \
			stable"
		sudo apt update

                apt-cache madison docker-ce
                echo "输入需要下载的版本号："
                read VERSION_STRING
                sudo apt install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io

		sudo mkdir -p /etc/docker
		sudo tee /etc/docker/daemon.json <<-'EOF'
		{
		  "registry-mirrors": ["https://wc087snh.mirror.aliyuncs.com"]
		}
		EOF
		sudo systemctl daemon-reload
		sudo systemctl restart docker
		
		sudo docker run hello-world
esac


